<?php

class FIN_newsBean
{

   
    
    function getAllNews($db){
    	$sql = "SELECT * FROM ".TBL_NEWS." ORDER BY news_date DESC";
    			
    	$res = $db->get_results($sql);
    	
    	return $res;
    }
	
	function count_news($db)
    {
    	$sql = "SELECT COUNT(news_id) as total FROM ".TBL_NEWS;
    			
    	$res = $db->get_row($sql);
    	
    	return $res->total;
    }
    function getAllNewsSharePage($db,$langid,$share, $list){
		$page = isset ( $_GET[$list] ) ? intval ( $_GET[$list] ) : 1;
		$rows_per_page= $share;
		$page_start = ( $page - 1 ) * $rows_per_page;
		$page_end = $page * $rows_per_page;
	
		$strSQL = "SELECT *,DATE_FORMAT(n.news_date,'%d/%m/%Y') as date FROM ".TBL_NEWS." n ".
				"LEFT JOIN ".TBL_NEWS_LANG." nl ON n.news_id = nl.news_id AND nl.lang_id = '$langid' ".
				" ORDER BY n.news_date ASC LIMIT $page_start, $rows_per_page";
		
		$res = $db->get_results($strSQL);
		return $res;	
    }
    
	
	function getNews($db,$langid, $id)
    {
    	$sql = "SELECT *,DATE_FORMAT(n.news_date,'%d/%m/%Y') as date FROM ".TBL_NEWS." n ".
				"LEFT JOIN ".TBL_NEWS_LANG." l ON n.news_id = l.news_id AND l.lang_id = '$langid' ".
				"WHERE n.news_id='$id'";
    			
    	$res = $db->get_row($sql);
    	
    	return $res;
    }
    
    function getHomeNews($db)
    {
    	$sql = "SELECT * FROM ".TBL_NEWS." ORDER BY news_date DESC LIMIT 0,".MAX_DEMO_NEWS_HOME;
    			
    	$res = $db->get_results($sql);
    	
    	return $res;
    }
    
	
}
?>